home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Examples / GUI / Advanced / enumicons.au3 < prev    next >
Encoding:
Text File  |  2007-09-08  |  7.7 KB  |  199 lines

  1. ;===============================================================================
  2. ;
  3. ; Description:      Show all icons in the given file
  4. ; Requirement(s):   Autoit 3.2.5+ and Dllcallback.au3 UDF
  5. ; Author(s):        YDY (Lazycat)
  6. ; Version:          2.0
  7. ; Date:             02.08.2007
  8. ;
  9. ;===============================================================================
  10. #include <GUIConstants.au3>
  11. #include "DllCallBack.au3"
  12.  
  13. ; Setting variables
  14. Global $BTN_STYLE = BitOR($BS_CHECKBOX, $BS_PUSHLIKE, $BS_FLAT)
  15. Global $ahIcons[30], $ahLabels[30]
  16. Global $iStartIndex = 1, $iCntRow, $iCntCol, $iCurIndex
  17. Global $glFilename = @SystemDir & "\shell32.dll"; Default file is "shell32.dll"
  18. Global $bOrdinal = true
  19. Global $glNames[1]
  20. Global $hSelected
  21.  
  22. ; Creating GUI and controls
  23. $hGui=GUICreate("Icon Selector by Ordinal value", 385, 435, -1, -1, -1, $WS_EX_ACCEPTFILES)
  24. GUICtrlCreateGroup("", 5, 1, 375, 40)
  25. GUICtrlCreateGroup("", 5, 50, 375, 380)
  26. $hFile = GUICtrlCreateInput($glFilename, 12,  15, 325, 16, -1, $WS_EX_STATICEDGE)
  27. GUICtrlSetState(-1, $GUI_DROPACCEPTED)
  28. GUICtrlSetTip(-1, "You can drop files from shell here...")
  29. $hStatus = GUICtrlCreateInput("", 155, 49, 125, 16, $ES_READONLY, $WS_EX_STATICEDGE)
  30. $hFileSel = GUICtrlCreateButton("...", 345,  14, 26, 18)
  31. $hPrev = GUICtrlCreateButton("Previous", 10,  45, 60, 24, $BTN_STYLE)
  32. GUICtrlSetState(-1, $GUI_DISABLE)
  33. $hNext = GUICtrlCreateButton("Next", 75,  45, 60, 24, $BTN_STYLE)
  34. $hToggle = GUICtrlCreateButton("by Name", 300,  45, 60, 24, $BTN_STYLE)
  35. $hOverlay = GUICtrlCreateLabel("", -99, -99 , 60, 62, $SS_GRAYFRAME)
  36. $hContext = GUICtrlCreateContextMenu($hOverlay)
  37. $hCopyIndex = GUICtrlCreateMenuItem("Copy Ordinal Value", $hContext)
  38. $hCopyName = GUICtrlCreateMenuItem("Copy Resource Name", $hContext)
  39.  
  40. ; This code build two arrays of ID's of icons and labels for easily update
  41. For $iCntRow = 0 to 4
  42.     For $iCntCol = 0 to 5
  43.         $iCurIndex = $iCntRow * 6 + $iCntCol
  44.         $ahIcons[$iCurIndex]  = GUICtrlCreateIcon($glFilename, 0, 60 * $iCntCol + 25, 70 * $iCntRow + 80)
  45.         $ahLabels[$iCurIndex] = GUICtrlCreateLabel("", 60 * $iCntCol+12, 70 * $iCntRow + 115, 58, 20, $SS_CENTER)
  46.     Next
  47. Next
  48.  
  49. _NewFileLoad($glFilename)
  50. _GUIUpdate()
  51.  
  52. GUISetState()
  53.  
  54. While 1
  55.     $aInfo = GUIGetCursorInfo()
  56.     If IsArray($aInfo) Then
  57.         If ($aInfo[4] >= $ahIcons[0] and $aInfo[4] <= $ahLabels[29]) Then
  58.             If $hSelected = $aInfo[4] Then ContinueLoop
  59.             $pos = ControlGetPos($hGUI, "", $aInfo[4])
  60.             If $pos[2] = 58 Then ; Label
  61.                 GuiCtrlSetPos($hOverlay, $pos[0] - 1, $pos[1] + $pos[3] - 60)
  62.             Else ; Icon
  63.                 GuiCtrlSetPos($hOverlay, $pos[0] - 14, $pos[1] - 5)
  64.             EndIf
  65.             $hSelected = $aInfo[4]
  66.         EndIf
  67.     EndIf
  68.     $nMsg = GUIGetMsg()
  69.     Switch $nMsg
  70.         Case $hCopyName, $hCopyIndex
  71.             For $i = 0 To 29
  72.                 If ($ahIcons[$i] = $hSelected or $ahLabels[$i] = $hSelected) and ($i + $iStartIndex <= $glNames[0]) Then
  73.                     If $nMsg = $hCopyName Then
  74.                         ClipPut($glNames[$i + $iStartIndex])
  75.                     Else
  76.                         ClipPut(-($i + $iStartIndex))
  77.                     EndIf
  78.                 EndIf
  79.             Next
  80.         Case $GUI_EVENT_DROPPED
  81.             $glFileName = @GUI_DragFile
  82.             GUICtrlSetData($hFile, $glFileName)
  83.             _NewFileLoad($glFileName)
  84.             _GUIUpdate()
  85.         Case $hFileSel
  86.             $sTmpFile = FileOpenDialog("Select file:", GUICtrlRead($hFile), "Executables & dll's (*.exe;*.dll;*.ocx;*.icl)")
  87.             If @error Then ContinueLoop
  88.             $glFileName = $sTmpFile
  89.             GUICtrlSetData($hFile, $glFileName)
  90.             _NewFileLoad($glFileName)
  91.             _GUIUpdate()
  92.         Case $hPrev
  93.             $iStartIndex = $iStartIndex - 30
  94.             _GUIUpdate()
  95.         Case $hNext
  96.             $iStartIndex = $iStartIndex + 30
  97.             _GUIUpdate()
  98.         Case $hToggle
  99.             $bOrdinal = not $bOrdinal
  100.             _SetMode()
  101.             _GUIUpdate()
  102.         Case $GUI_EVENT_CLOSE
  103.             Exit
  104.     EndSwitch
  105. Wend
  106.  
  107. ; Updates GUI icons, labels and state of navigate buttons
  108. Func _GUIUpdate()
  109.     For $iCntRow = 0 to 4
  110.         For $iCntCol = 0 to 5
  111.             $iCurIndex = $iCntRow * 6 + $iCntCol
  112.             If ($iCurIndex + $iStartIndex) > $glNames[0] Then
  113.                 GUICtrlSetState($ahIcons[$iCurIndex], $GUI_HIDE)
  114.                 GUICtrlSetState($ahLabels[$iCurIndex], $GUI_HIDE)
  115.             Else
  116.                 GUICtrlSetState($ahIcons[$iCurIndex], $GUI_SHOW)
  117.                 GUICtrlSetState($ahLabels[$iCurIndex], $GUI_SHOW)
  118.                 If $bOrdinal then
  119.                     GUICtrlSetImage($ahIcons[$iCurIndex], $glFileName, -($iStartIndex + $iCurIndex))
  120.                     GUICtrlSetData($ahLabels[$iCurIndex], -($iStartIndex + $iCurIndex))
  121.                 Else
  122.                     GUICtrlSetImage($ahIcons[$iCurIndex], $glFileName, $glNames[$iStartIndex + $iCurIndex])
  123.                     GUICtrlSetData($ahLabels[$iCurIndex], '"' & $glNames[$iStartIndex + $iCurIndex] & '"')
  124.                 EndIf
  125.             EndIf
  126.         Next
  127.     Next
  128.  
  129.     ; Keep icons in bounds
  130.     If $iStartIndex = 1 Then
  131.         GUICtrlSetState($hPrev, $GUI_DISABLE)
  132.     Else
  133.         GUICtrlSetState($hPrev, $GUI_ENABLE)
  134.     Endif
  135.     If $iStartIndex + 30 > $glNames[0] Then
  136.         GUICtrlSetState($hNext, $GUI_DISABLE)
  137.     Else
  138.         GUICtrlSetState($hNext, $GUI_ENABLE)
  139.     Endif
  140.     $iToNumber = $iStartIndex + 29
  141.     If $iToNumber > $glNames[0] Then $iToNumber = $iToNumber - ($iToNumber - $glNames[0])
  142.     GUICtrlSetData($hStatus, " " & $iStartIndex & " - " & $iToNumber & " from " & $glNames[0])
  143. EndFunc
  144.  
  145. Func _SetMode()
  146.     If $bOrdinal Then
  147.         GUICtrlSetData($hToggle, "by Name")
  148.         WinSetTitle($hGui,"","Icon Selector by Ordinal value")
  149.     Else
  150.         GUICtrlSetData($hToggle, "by Ordinal")
  151.         WinSetTitle($hGui,"","Icon Selector by Name value")
  152.     EndIf
  153. EndFunc
  154.  
  155. Func _NewFileLoad($sFilename)
  156.     GuiCtrlSetPos($hOverlay, -99, -99)
  157.     $iStartIndex = 1
  158.     ReDim $glNames[1]
  159.     ; ICL is 16-bit library, we can't load it with LoadLibrary... maybe any other good way?
  160.     If StringRight($sFilename, 4) = ".icl" Then
  161.         $glNames[0] =  _GetIconCount($sFilename)
  162.         $bOrdinal = True
  163.         GUICtrlSetState($hToggle, $GUI_DISABLE)
  164.         GUICtrlSetState($hCopyName, $GUI_DISABLE)
  165.         _SetMode()
  166.         Return 1
  167.     EndIf
  168.     GUICtrlSetState($hToggle, $GUI_ENABLE)
  169.     GUICtrlSetState($hCopyName, $GUI_ENABLE)
  170.     $glNames[0] = 0
  171.     Local $hMod = DllCall("Kernel32.dll", "int", "LoadLibraryEx", "str", $sFilename, "int", 0, "int", 0x22)
  172.     If $hMod[0] = 0 Then
  173.         MsgBox (48, "Error", "Not a library or can't load library.")
  174.         Return 0
  175.     EndIf
  176.     $hMod = $hMod[0]
  177.     Local $hStub_EnumResNames = _DllCallBack("_EnumResNames", "int;ptr;ptr;ptr")
  178.     DllCall("kernel32.dll", "int:stdcall", "EnumResourceNames", "int", $hMod, "ptr", 14, "ptr", $hStub_EnumResNames, "long_ptr", 0)
  179.     _DllCallBack_Free ($hStub_EnumResNames)
  180.     DllCall("Kernel32.dll", "int", "FreeLibrary", "int", $hMod)
  181. EndFunc
  182.  
  183. Func _EnumResNames($hModule, $lpType, $lpName, $lParam)
  184.     $glNames[0] += 1
  185.     ReDim $glNames[$glNames[0]+1]
  186.     If BitAND($lpName, 0xFFFF0000) Then
  187.         Local $s = DllStructCreate("char[256]", $lpName)
  188.         $glNames[$glNames[0]] = DllStructGetData($s, 1)
  189.     Else
  190.         $glNames[$glNames[0]] = $lpName
  191.     EndIf
  192.     Return 1
  193. EndFunc
  194.  
  195. Func _GetIconCount($sFilename)
  196.     Local $iCount= DllCall("Shell32", "int", "ExtractIconEx", "str", $sFilename, "int", -1, "ptr", 0, "ptr", 0, "int", 1)
  197.     If not @error Then Return $iCount[0]
  198.     Return 0
  199. EndFunc